﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class LevelTileUI : MonoBehaviour,IPointerClickHandler
{
    public event Action<LevelTileUI> Clicked; 

    [SerializeField] private Text _lvlTxt;
    [SerializeField] private GameObject _lockEffect;
    [SerializeField] private GameObject _completeEffect;
    [SerializeField] private CanvasGroup _canvasGroup;


    private ILevel _level;
    private Status _currentStatus;  

    public ILevel Level
    {
        get => _level;
        set
        {
            _lvlTxt.text = value.LevelNo.ToString();
            _level = value;
        }
    }

    public Status CurrentStatus
    {
        get => _currentStatus;
        set
        {
            _currentStatus = value;
            
            _canvasGroup.alpha = value == Status.Locked ? 0.6f : 1f;
            
            if(_lockEffect)
            _lockEffect.SetActive(value == Status.Locked);
            
            if(_completeEffect)
            _completeEffect.SetActive(value == Status.Completed);
        }
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        Clicked?.Invoke(this);
    }

    public enum Status
    {
        Locked,Unlocked,Completed
    }
}